<?php
namespace Admin\Controller;
use Think\Controller;
class ActController extends Controller {
    public function lists(){
    	$act = M("act");
        $arr = $act->select();
        $this->assign("arr",$arr);
        $this->display();
    }
    //添加
	public function add(){
		$this->display();
	}
    public function doadd(){
    	        //上传文件
	    $upload = new \Think\Upload();// 实例化上传类   
	     $upload->maxSize  =  3145728 ;// 设置附件上传大小    
	     $upload->exts     =  array('jpg','gif','png','jpeg');// 设置附件上传类型 
	     $upload->rootPath =  './Public/Uploads/'; // 设置附件上传根目录    
	     $upload->savePath =  ''; // 设置附件上传（子）目录    
	     // 上传文件     
	     $info   =   $upload->upload();    
	    if(!$info) {// 上传错误提示错误信息        
	     	$this->error($upload->getError());    
	     }else{  
	     	// 上传成功  
	     	$photo = $info['act_picture']['savepath'].$info['act_picture']['savename'];
	     	$photo2=$info['act_picture']['savepath'].'upload_2_'.$info['act_picture']['savename'];
	     	 $this->thumb('./Public/Uploads/'.$photo,'./Public/Uploads/'.$photo2,50);
			//$this->success('上传成功！');    	
	}  
		$act = D('act');
		$_POST['act_picture']=$photo;
		
		if($act->create($_POST)){
			$act->add();
			$this->success('添加成功',U('Act/lists'));
		}else{
			$this->error('添加失败',U('Act/add'));
			
		}
    }
    private function thumb($imgurl,$thumburl,$size){
		//切割图片
		$image = new \Think\Image();
		$image->open($imgurl);
		$image->thumb($size,$size,1)->save($thumburl);
	}

    //修改
	public function edit(){
		$act_id = $_GET['uid'];
 		//print_r($act_id);
		$vo = M('act')->where("act_id={$act_id}")->select();
		$this->assign('vvo',$vo);		
		$this->display();
	}

	public function doedit(){
		//上传文件
	    $upload = new \Think\Upload();// 实例化上传类   
	     $upload->maxSize  =  3145728 ;// 设置附件上传大小    
	     $upload->exts     =  array('jpg','gif','png','jpeg');// 设置附件上传类型 
	     $upload->rootPath =  './Public/Uploads/'; // 设置附件上传根目录    
	     $upload->savePath =  ''; // 设置附件上传（子）目录    
	     // 上传文件     
	     $info   =   $upload->upload();    
	    if(!$info) {// 上传错误提示错误信息        
	     	$this->error($upload->getError());    
	     }else{  
	     	// 上传成功  
	     	$photo = $info['act_picture']['savepath'].$info['act_picture']['savename'];
	     	$photo2=$info['act_picture']['savepath'].'upload_2_'.$info['act_picture']['savename'];
	     	 $this->thumb('./Public/Uploads/'.$photo,'./Public/Uploads/'.$photo2,50);
			//$this->success('上传成功！');    	
	}
		$act = D('act');
		$_POST['act_picture']=$photo;
		
		
		if($act->create($_POST)){
			$act->save();
			$this->success('编辑成功',U('Act/lists'));
		}else{
			$this->error('编辑失败',U('Act/edit'));
			
		}
    }
	


	//删除
    public function del(){
		$uid = I('uid');
		$res = M('act')->delete($uid);
		$r = array();
		if($res){
			$r['msg']='删除成功';
			$r['status']=true;
		}else{
			$r['msg']='删除失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}
}